from django.db import models
from django.contrib.auth.models import User
from utils.modelsMixin import ModelSetMixin


# Create your models here.
class Label(models.Model):
    name = models.CharField(max_length=30, verbose_name='标签名', unique=True)
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        db_table = 'label'
        verbose_name = '标签'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Topic(ModelSetMixin):
    TYPE_CHOICES = (
        (0, '单选题'),
        (1, '多选题'),
        (2, '判断题'),
        (3, '填空题'),
        (4, '问答题')
    )
    subject = models.TextField(verbose_name='题干')
    type = models.IntegerField(verbose_name='类型', choices=TYPE_CHOICES)
    score = models.FloatField(verbose_name='分值', default=1.0, null=True, blank=True)
    description = models.TextField(verbose_name='题目描述', null=True, blank=True)
    answer = models.TextField(verbose_name='答案')

    label = models.ForeignKey(Label, on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        ordering = ['-update_time']
        db_table = 'topic'
        verbose_name = '题目'
        verbose_name_plural = verbose_name
